package com.cupk.rotaryguard.user.controller;

import com.cupk.common.base.utils.result.Result;
import com.cupk.common.base.utils.result.ResultGenerator;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试redis连接
 *
 * @author tjy
 * @date 2023/3/24
 * @apiNote
 */
@RestController
@RequestMapping("/redis-test")
public class RedisTestController {
    @Resource
    private RedisTemplate redisTemplate;

    @RequestMapping("/set")
    public Result setVal(String key, String val) {
        redisTemplate.opsForValue().set(key, val);
        return ResultGenerator.genSuccessResult("success");
    }

    @RequestMapping("/get")
    public Result getVal(String val) {
        return ResultGenerator.genSuccessResult(redisTemplate.opsForValue().get(val), "获取成功");
    }
}
